home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / mhis020.zip / DATE.MH < prev    next >
Text File  |  1996-09-16  |  2KB  |  80 lines

  1. #ifndef __DATE_MH
  2. #define __DATE_MH
  3.  
  4. string date_string (struct _date: d) {
  5.   return (itostr ((d.year + 80) % 100) + "\\" + strpadleft (itostr (d.month),2,'0') + "\\"
  6.     + strpadleft (itostr (d.day),2,'0'));
  7.   }
  8.  
  9. void string_to_date (Ref struct _date: d, string: str) {
  10.   int: idx, idx2;
  11.   long: current_date;
  12.   struct _stamp: cur_date_stamp;
  13.  
  14.   idx := stridx (str, 1, '\\');
  15.   idx2 := stridx (str, idx + 1, '\\');
  16.  
  17.   if (idx2) {
  18.     d.year := strtoi (substr (str, 1, idx - 1)) - 80;
  19.     d.month := strtoi (substr (str, idx + 1, idx2 - idx));
  20.     d.day := strtoi (substr (str, idx2 + 1, strlen (str) - idx2));
  21.     }
  22.   else {
  23.     current_date := time ();
  24.     long_to_stamp (current_date, cur_date_stamp);
  25.     d.year := cur_date_stamp.date.year;
  26.     d.month := strtoi (substr (str, 1, idx - 1));
  27.     d.day := strtoi (substr (str, idx + 1, strlen (str) - idx));
  28.     };
  29.   }
  30.  
  31. // returns true if d1 > d2
  32.  
  33. int date_greater (struct _date: d1, struct _date: d2) {
  34.   if (d1.year > d2.year) return True;
  35.   if (d1.year = d2.year) {
  36.     if (d1.month > d2.month) return True;
  37.     if (d1.month = d2.month) {
  38.       if (d1.day > d2.day) return True;
  39.       };
  40.     };
  41.   return False;
  42.   }
  43.  
  44. string time_to_string (struct _time: tme) {
  45.   string: result;
  46.   string: temp;
  47.   result := itostr (tme.hh);
  48.   if (strlen (result) < 2) result := "0" + result;
  49.   if (tme.mm < 10) {
  50.     temp := "0" + itostr (tme.mm);
  51.     }
  52.   else temp := itostr (tme.mm);
  53.   result := result + ":" + temp;
  54.   return result;
  55.   }
  56.  
  57. string seconds_to_string (unsigned long: seconds) {
  58.   int: hours, days, minutes;
  59.   string: tempstr, result;
  60.  
  61.   hours := seconds / 3600;
  62.   days := hours / 24;
  63.   hours := hours % 24;
  64.   seconds := seconds % 3600;
  65.   minutes := seconds / 60;
  66.   if (days > 0) {
  67.     result := itostr (days) + " day";
  68.     if (days > 1) 
  69.       result := result + "s";
  70.     result := result + ", " + itostr (hours)
  71.               + ":" + strpadleft (itostr (minutes), 2, '0');
  72.     }
  73.   else {
  74.     result := strpadleft (itostr (hours),2,'0') + ":" + strpadleft (itostr (minutes), 2, '0');
  75.     };
  76.   return result;
  77.   }
  78.  
  79. #endif
  80.